package T4.EjemplosDelSwing.ejemplosgui;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class Frame extends JFrame implements ActionListener {

    private JPanel panel = new JPanel();
    private JButton azul, rosa, amarillo, verde;

    public Frame() {
        setTitle("Hola!!!");
        setSize(500, 400);
        addWindowListener(new manejador10());
        Container contentpane = getContentPane();
        panel.setLayout(new BorderLayout());

        azul = new JButton("Azul");
        azul.addActionListener(this);
        Dimension tamano = new Dimension();
        tamano.height = 40;
        tamano.width = 100;
        azul.setPreferredSize(tamano);

        verde = new JButton("Verde");
        verde.addActionListener(this);
        verde.setPreferredSize(tamano);

        amarillo = new JButton("Amarillo");
        amarillo.addActionListener(this);
        amarillo.setPreferredSize(tamano);

        rosa = new JButton("Rosa");
        rosa.addActionListener(this);
        rosa.setPreferredSize(tamano);
        panel.add(azul, BorderLayout.SOUTH);
        panel.add(verde, BorderLayout.NORTH);
        panel.add(amarillo, BorderLayout.EAST);
        panel.add(rosa, BorderLayout.WEST);

        contentpane.add(panel);
        panel.setBackground(Color.red);


    }

    @Override
    public void actionPerformed(ActionEvent e) {
        Object source = e.getSource();
        if (source == azul) {
            panel.setBackground(Color.blue);
        }
        if (source == verde) {
            panel.setBackground(Color.green);
        }
        if (source == amarillo) {
            panel.setBackground(Color.yellow);
        }
        if (source == rosa) {
            panel.setBackground(Color.pink);
        }

    }
}

class manejador10 extends WindowAdapter {

    @Override
    public void windowClosing(WindowEvent e) {
        System.exit(0);
    }
}

public class Ejemplo10 {

    public static void main(String[] args) {
        JFrame frame = new Frame();
        frame.setVisible(true);
    }
}
